package org.hs.phd.odi.tracking.filters;

import org.hs.phd.common.simpleplayer.ImageSequenceFrame;
import org.hs.phd.common.simpleplayer.PlayerEvent;
import org.hs.phd.common.simpleplayer.PlayerFilter;
import org.hs.phd.common.simpleplayer.PlayerListener;
import org.hs.phd.odi.tracking.tracker.TrackerGroup;

public class TracksFilter implements PlayerFilter, PlayerListener {
	
	private final TrackerGroup trackers;

	public TracksFilter(TrackerGroup trackers){
		this.trackers = trackers;
	}

	@Override
	public void playerEventOccurred(PlayerEvent event) {
		if( ! (event instanceof TrackSelectionEvent) ) return;

		TrackSelectionEvent initializationEvent = (TrackSelectionEvent) event;
		
		trackers.initTrackers(initializationEvent.getSelectionShape(), 
				event.getPlayer().getCurrentFrame());
		
		event.getPlayer().refreshViewer();
	}

	@Override
	public void filter(ImageSequenceFrame input) {
		trackers.updateWithNextFrame(input);
		
		
	}

}
